#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1005;
const int M = 1e9 + 7;
int a[N];

bool check(int x)
{
    if (x % 3 == 0 || x % 10 == 3)
        return false;

    return true;
}
void init()
{
    int i = 1, j = 1;
    while(j <= 1000) {
        a[j++] = i++;
        while(!check(i)) i++;
    }
}

int t, n;
int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    init();
    cin >> t;
    while (t--)
    {
        cin >> n;
        cout << a[n] << endl;
    }
    return 0;
}